home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 2 / Mac Magazin and MacEasy Magazine CD - Issue 02.iso / Sharewarebibliothek / Applikationen / Alpha.5.81 folder / Tcl / SystemCode / latex.tcl < prev    next >
Text File  |  1994-06-13  |  57KB  |  2,584 lines

  1. #############################################################################
  2. #
  3. # latex.tcl:  macros and bindings for LaTeX users
  4. #
  5. # -- see files 'LaTeX Help' and 'commands.tex' in the Help folder
  6. #
  7. #############################################################################
  8. #
  9. # version 1.1 and 1.2 (11/10/92) by Richard T. Austin (austin@eecs.umich.edu)
  10. # version 2.0 (1/24/93) by Tom Scavo (scavo@cie.uoregon.edu)
  11. #
  12. # If you make improvements to this file, please share them!
  13. #
  14. #############################################################################
  15.  
  16. source "$HOME:Tcl:UserCode:smart.tcl"
  17.  
  18. #############################################################################
  19. #
  20. # Flags and Variables.
  21. #
  22. #############################################################################
  23.  
  24. set true 1
  25. set false 0
  26. # set insertLatexParameter $true
  27. # set noInsertLatexParameter $false
  28.  
  29. initTclFlag useBoxMacro
  30. initTclFlag deleteObjectNoisily
  31. initTclFlag deleteEnvironmentNoisily
  32. set useBoxMacro $true
  33. set deleteObjectNoisily $false
  34. set deleteEnvironmentNoisily $true
  35. initTclVar boxMacroName
  36. set boxMacroName "BoxedEPSF"
  37.  
  38. proc GoTeX {menu item} {dosc -c '*TEX' -s [getText 0 [maxPos]] -r}
  39. menu -n "$texturesMenu" -p GoTeX {Typeset}
  40.  
  41.  
  42. #############################################################################
  43. #
  44. # Utility Macros.
  45. #
  46. #############################################################################
  47.  
  48. # A boolean function which checks to see if there's a current selection.
  49. proc isSelection {} {
  50.     return [string length [getSelect]]
  51. }
  52.  
  53. # Select the line containing the insertion point.
  54. proc lineSelect {} {
  55.     goto [lineStart [getPos]]
  56.     nextLineSelect
  57. }
  58.  
  59. # A boolean function which takes any string and tests to see if
  60. # that string contains all whitespace characters.  Carriage returns 
  61. # are considered whitespace, as are spaces and tabs.
  62. proc isWhitespace {anyString} {
  63.     set len [string length $anyString]
  64.     for {set i 0} {$i < $len} {incr i} {
  65.         set c [string index $anyString $i]
  66.         if {($c != "\ ") && ($c != "\t") && ($c != "\r")} then {return 0}
  67.     }
  68.     return 1
  69. }
  70.  
  71. # Insert a carriage return at the insertion point if any
  72. # character preceding the insertion point (on the same line)
  73. # is a non-whitespace character.
  74. proc openingCarriageReturn {} {
  75.     set end [getPos]
  76.     set start [lineStart $end]
  77.     set text [getText $start $end]
  78.     if {![isWhitespace $text]} carriageReturn
  79. }
  80.  
  81. # Insert a carriage return at the insertion point if any
  82. # character following the insertion point (on the same line)
  83. # is a non-whitespace character.
  84. proc closingCarriageReturn {} {
  85.     set start [getPos]
  86.     set end [nextLineStart $start]
  87.     set text [getText $start $end]
  88.     if {![isWhitespace $text]} carriageReturn
  89. }
  90.  
  91. # Set up tab stop mechanism.
  92. proc gotoTabStop {directionIndicator} {
  93.     set searchResult [search -n -f $directionIndicator -m 0 -i 1 -r 0 {•} [getPos]]
  94.     if {[llength $searchResult] == 0} then {
  95.         message "tab stop not found"
  96.         return 0
  97.     } else {
  98.         goto [lindex $searchResult 0]
  99.         return 1
  100.     }
  101. }
  102. proc nextTabStop {} {
  103.     if {[gotoTabStop 1]} {deleteChar}
  104. }
  105. proc previousTabStop {} {
  106.     if {[gotoTabStop 0]} {deleteChar}
  107. }
  108.  
  109. # Insert an object at the insertion point. If there is a selection and the 
  110. # global variable deleteObjectNoisily is false, quietly delete the selection 
  111. # first (just like "paste"). Otherwise, prompt the user for the appropriate 
  112. # action. Returns true if the object is ultimately inserted, and false if the 
  113. # user cancels the operation. 
  114. proc insertObject {objectName} {
  115.     global deleteObjectNoisily
  116.     if {[isSelection]} then {
  117.         if {$deleteObjectNoisily} then {
  118.             case [askyesno "Delete selection?"] in {
  119.                 "yes" {deleteText [getPos] [selEnd]}
  120.                 "no" {backwardChar}
  121.                 "cancel" {return 0}
  122.             }
  123.         } else {
  124.             deleteText [getPos] [selEnd]
  125.         }
  126.     }
  127.     insertText $objectName
  128.     return 1
  129. }
  130.  
  131. # Insert an object at the insertion point. If there is a selection, wrap 
  132. # it inside the parameters $left and $right. Returns true if there is a 
  133. # selection (in which case it will wrap), and false otherwise. 
  134. proc wrapObject {left right} {
  135.     set currentPos [getPos]
  136.     set selected [isSelection]
  137.     if {$selected} then {
  138.         replaceText $currentPos [selEnd] $left [getSelect] $right
  139.     } else {
  140.         insertText $left "•" $right
  141.     }
  142.     goto $currentPos
  143.     nextTabStop
  144.     return $selected
  145. }
  146.  
  147. # Inserts an environment with the specified name at the insertion point. 
  148. # Preserves indentation, and positions the cursor at the beginning of the 
  149. # environment body (to be inserted by the calling procedure). If the 
  150. # parameter latexParameter is true, a LaTeX parameter is inserted and the 
  151. # cursor is positioned there instead. Deletes the current selection quietly 
  152. # if the global variable deleteEnvironmentNoisily is false; otherwise the 
  153. # user is prompted for directions. Returns true if the environment is 
  154. # ultimately inserted, and false if the user cancels the operation. 
  155. proc insertEnvironment {environmentName latexParameter} {
  156.     global deleteEnvironmentNoisily
  157.     if {[isSelection]} then {
  158.         if {$deleteEnvironmentNoisily} then {
  159.             case [askyesno "Delete selection?"] in {
  160.                 "yes" {deleteText [getPos] [selEnd]}
  161.                 "no" {backwardChar}
  162.                 "cancel" {return 0}
  163.             }
  164.         } else {
  165.             deleteText [getPos] [selEnd]
  166.         }
  167.     }
  168.     set currentPos [getPos]
  169.     openingCarriageReturn
  170.     insertText "\\begin{" $environmentName "}"
  171.     # insert optional LaTeX parameter here:
  172.     if {$latexParameter} {insertText "{•}"}
  173.     carriageReturn
  174.     tab
  175.     insertText "•"
  176.     carriageReturn
  177.     backwardChar
  178.     deleteChar
  179.     insertText "\\end{" $environmentName "}•"
  180.     closingCarriageReturn
  181.     goto $currentPos
  182.     nextTabStop
  183.     return 1
  184. }
  185.  
  186. # Insert an environment with the given name at the insertion point. If there 
  187. # is currently a selection, cut and paste it into the body of the new 
  188. # environment, indent it, and leave it highlighted. Returns true if there is 
  189. # a selection, and false otherwise. 
  190. proc wrapEnvironment {environmentName latexParameter} {
  191.     if {[isSelection]} then {
  192.         set indent [indentString [getPos]]
  193.         set text [getSelect]
  194.         deleteText [getPos] [selEnd]
  195.         insertText $indent "\r"
  196.         backwardChar
  197.         insertEnvironment $environmentName $latexParameter
  198.         if {$latexParameter} then {
  199.             insertText "•"
  200.             nextTabStop
  201.         }
  202.         lineSelect
  203.         clear
  204.         insertText $text
  205.         markHilite
  206.         shiftRight
  207.         return 1
  208.     } else {
  209.         insertEnvironment $environmentName $latexParameter
  210.         return 0
  211.     }
  212. }
  213.  
  214.  
  215. #############################################################################
  216. # Paragraph Mode Macros.
  217. #
  218. #############################################################################
  219.  
  220. # Documents:
  221. proc insertDocument {documentType} {
  222.     set currentPos [getPos]
  223.     insertText "\\documentstyle\[•\]{$documentType}"
  224.     carriageReturn
  225.     insertEnvironment "document" 0
  226.     backwardChar
  227.     deleteChar
  228.     carriageReturn
  229.     insertText "•"
  230.     carriageReturn
  231.     nextTabStop
  232.     carriageReturn
  233.     goto $currentPos
  234.     nextTabStop
  235. }
  236. proc isDocumentSelected {} {
  237.     return 1
  238. }
  239. proc isEmptyFile {} {
  240.     return 1
  241. }
  242. proc wrapDocument {documentType} {
  243.     if {[isSelection]} then {
  244.         if {[isDocumentSelected]} then {
  245.             set text [getSelect]
  246.             deleteText [getPos] [selEnd]
  247.         } else {
  248.             case [askyesno "Select entire document?"] in {
  249.                 "yes" {}
  250.                 "no" {
  251.                     set text [getSelect]
  252.                     deleteText [getPos] [selEnd]
  253.                 }
  254.                 "cancel" {return 0}
  255.             }
  256.         }
  257.         set currentPos [getPos]
  258.         insertDocument $documentType
  259.         insertText "•"
  260.         nextTabStop
  261.         lineSelect
  262.         clear
  263.         insertText $text
  264.         markHilite
  265.         nextTabStop
  266.     } else {
  267.         if {![isEmptyFile]} then {
  268.             case [askyesno "Wrap existing text?"] in {
  269.                 "yes" {}
  270.                 "no" {}
  271.                 "cancel" {return 0}
  272.             }
  273.         }
  274.         insertDocument $documentType
  275.     }
  276.     return 1
  277. }
  278.  
  279. proc letter {} {
  280.     wrapDocument "letter"
  281.     message "type style option(s)"
  282. }
  283. proc article {} {
  284.     wrapDocument "article"
  285.     message "type style option(s)"
  286. }
  287. proc report {} {
  288.     wrapDocument "report"
  289.     message "type style option(s)"
  290. }
  291. proc book {} {
  292.     wrapDocument "book"
  293.     message "type style option(s)"
  294. }
  295.  
  296. proc custom {} {
  297.     catch {prompt "What document type?" "article"} documentType
  298.     if {$documentType != "cancel"} then {
  299.         wrapDocument $documentType
  300.         message "type style option(s)"
  301.     }
  302. }
  303.  
  304. # Sectioning:
  305. proc part {} {
  306.     if {[wrapObject "\\part{" "}•"]} then {
  307.         message "don't forget label"
  308.     } else {
  309.         message "type part name"
  310.     }
  311. }
  312. proc chapter {} {
  313.     if {[wrapObject "\\chapter{" "}•"]} then {
  314.         message "don't forget label"
  315.     } else {
  316.         message "type part name"
  317.     }
  318. }
  319. proc section {} {
  320.     if {[wrapObject "\\section{" "}•"]} then {
  321.         message "don't forget label"
  322.     } else {
  323.         message "type part name"
  324.     }
  325. }
  326. proc subsection {} {
  327.     if {[wrapObject "\\subsection{" "}•"]} then {
  328.         message "don't forget label"
  329.     } else {
  330.         message "type part name"
  331.     }
  332. }
  333. proc subsubsection {} {
  334.     if {[wrapObject "\\subsubsection{" "}•"]} then {
  335.         message "don't forget label"
  336.     } else {
  337.         message "type part name"
  338.     }
  339. }
  340. proc paragraph {} {
  341.     if {[wrapObject "\\paragraph{" "}•"]} then {
  342.         message "don't forget label"
  343.     } else {
  344.         message "type part name"
  345.     }
  346. }
  347. proc subparagraph {} {
  348.     if {[wrapObject "\\subparagraph{" "}•"]} then {
  349.         message "don't forget label"
  350.     } else {
  351.         message "type part name"
  352.     }
  353. }
  354.  
  355. # Definitions:
  356. proc myList {} {alertnote "Not yet implemented."}
  357. proc newcommand {} {alertnote "Not yet implemented."}
  358. proc newenvironment {} {alertnote "Not yet implemented."}
  359. proc newtheorem {} {alertnote "Not yet implemented."}
  360. proc renewcommand {} {alertnote "Not yet implemented."}
  361. proc renewenvironment {} {alertnote "Not yet implemented."}
  362.  
  363. # Text Style:
  364. proc roman {} {
  365.     if {[wrapObject "{\\rm " "}•"]} then {
  366.         message "roman text set"
  367.     } else {
  368.         message "enter roman text"
  369.     }
  370. }
  371. proc bold {} {
  372.     if {[wrapObject "{\\bf " "}•"]} then {
  373.         message "bold text set"
  374.     } else {
  375.         message "enter bold text"
  376.     }
  377. }
  378. proc italic {} {
  379.     if {[wrapObject "{\\it " "\\/}•"]} then {
  380.         insertText "•"
  381.         backwardChar
  382.         backwardChar
  383.     }
  384.     message "italic correction?"
  385. }
  386. proc emphatic {} {
  387.     if {[wrapObject "{\\em " "\\/}•"]} then {
  388.         insertText "•"
  389.         backwardChar
  390.         backwardChar
  391.     }
  392.     message "emphatic correction?"
  393. }
  394. proc slanted {} {
  395.     if {[wrapObject "{\\sl " "\\/}•"]} then {
  396.         insertText "•"
  397.         backwardChar
  398.         backwardChar
  399.     }
  400.     message "italic correction?"
  401. }
  402. proc sansSerif {} {
  403.     if {[wrapObject "{\\sf " "}•"]} then {
  404.         message "sans serif text set"
  405.     } else {
  406.         message "enter sans serif text"
  407.     }
  408. }
  409. proc smallCaps {} {
  410.     if {[wrapObject "{\\sc " "}•"]} then {
  411.         message "small caps text set"
  412.     } else {
  413.         message "enter small caps text"
  414.     }
  415. }
  416. proc typewriter {} {
  417.     if {[wrapObject "{\\tt " "}•"]} then {
  418.         message "typewriter text set"
  419.     } else {
  420.         message "enter typewriter text"
  421.     }
  422. }
  423.  
  424. # Text Size:
  425. proc tiny {} {
  426.     if {[wrapObject "{\\tiny " "}•"]} then {
  427.         message "tiny text set"
  428.     } else {
  429.         message "enter tiny text"
  430.     }
  431. }
  432. proc smallest {} {
  433.     if {[wrapObject "{\\scriptsize " "}•"]} then {
  434.         message "scriptsize text set"
  435.     } else {
  436.         message "enter scriptsize text"
  437.     }
  438. }
  439. proc smaller {} {
  440.     if {[wrapObject "{\\footnotesize " "}•"]} then {
  441.         message "footnotesize text set"
  442.     } else {
  443.         message "enter footnotesize text"
  444.     }
  445. }
  446. proc small {} {
  447.     if {[wrapObject "{\\small " "}•"]} then {
  448.         message "small text set"
  449.     } else {
  450.         message "enter small text"
  451.     }
  452. }
  453. proc normal {} {
  454.     if {[wrapObject "{\\normalsize " "}•"]} then {
  455.         message "normalsize text set"
  456.     } else {
  457.         message "enter normalsize text"
  458.     }
  459. }
  460. proc large {} {
  461.     if {[wrapObject "{\\large " "}•"]} then {
  462.         message "large text set"
  463.     } else {
  464.         message "enter large text"
  465.     }
  466. }
  467. proc larger {} {
  468.     if {[wrapObject "{\\Large " "}•"]} then {
  469.         message "Large text set"
  470.     } else {
  471.         message "enter Large text"
  472.     }
  473. }
  474. proc largest {} {
  475.     if {[wrapObject "{\\LARGE " "}•"]} then {
  476.         message "LARGE text set"
  477.     } else {
  478.         message "enter LARGE text"
  479.     }
  480. }
  481. proc huge {} {
  482.     if {[wrapObject "{\\huge " "}•"]} then {
  483.         message "huge text set"
  484.     } else {
  485.         message "enter huge text"
  486.     }
  487. }
  488. proc gigantic {} {
  489.     if {[wrapObject "{\\Huge " "}•"]} then {
  490.         message "Huge text set"
  491.     } else {
  492.         message "enter Huge text"
  493.     }
  494. }
  495.  
  496. # International:  not yet implemented.
  497.  
  498. # Environments:
  499. proc enumerate {} {
  500.     catch {prompt "enumerate:  how many items?" 3} numberItems
  501.     if {$numberItems != "cancel"} then {
  502.         set currentPos [getPos]
  503.         if {[insertEnvironment "enumerate" 0]} then {
  504.             item
  505.             insertText "  •"
  506.             for {set i 1} {$i < $numberItems} {incr i} {
  507.                 carriageReturn
  508.                 carriageReturn
  509.                 item
  510.                 insertText "  •"
  511.             }
  512.             goto $currentPos
  513.             nextTabStop
  514.             message "Type first item"
  515.         }
  516.     }
  517. }
  518. proc itemize {} {
  519.     catch {prompt "itemize:  how many items?" 3} numberItems
  520.     if {$numberItems != "cancel"} then {
  521.         set currentPos [getPos]
  522.         if {[insertEnvironment "itemize" 0]} then {
  523.             item
  524.             insertText "  •"
  525.             for {set i 1} {$i < $numberItems} {incr i} {
  526.                 carriageReturn
  527.                 carriageReturn
  528.                 item
  529.                 insertText "  •"
  530.             }
  531.             goto $currentPos
  532.             nextTabStop
  533.             message "Type first item"
  534.         }
  535.     }
  536. }
  537. proc description {} {
  538.     catch {prompt "description: how many items?" 3} numberItems
  539.     if {$numberItems != "cancel"} then {
  540.         set currentPos [getPos]
  541.         if {[insertEnvironment "description" 0]} then {
  542.             item
  543.             insertText "\[•\]  •"
  544.             for {set i 1} {$i < $numberItems} {incr i} {
  545.                 carriageReturn
  546.                 carriageReturn
  547.                 item
  548.                 insertText "\[•\]  •"
  549.             }
  550.             goto $currentPos
  551.             nextTabStop
  552.             message "Type first item"
  553.         }
  554.     }
  555. }
  556.  
  557. proc insertRow {jmax} {
  558.     insertText "•"
  559.     for {set j 1} {$j < $jmax} {incr j} {
  560.         insertText " & •"
  561.     }
  562. }
  563. proc tabular {} {
  564.     catch {prompt "tabular:  how many rows?" 3} numberRows
  565.     if {$numberRows != "cancel"} then {
  566.         catch {prompt "tabular:  how many columns?" 3} numberCols
  567.         if {$numberCols != "cancel"} then {
  568.             if {[insertEnvironment "tabular" 1]} then {
  569.                 set beginArgument [getPos]
  570.                 insertText "|"
  571.                 for {set j 1} {$j <= $numberCols} {incr j} {
  572.                     insertText "c|"
  573.                 }
  574.                 set endArgument [getPos]
  575.                 nextTabStop
  576.                 insertText "\\hline"
  577.                 for {set i 1} {$i <= $numberRows} {incr i} {
  578.                     carriageReturn
  579.                     insertRow $numberCols
  580.                     insertText "  \\\\"
  581.                     carriageReturn
  582.                     insertText "\\hline"
  583.                 }
  584.                 goto $beginArgument
  585.                 setMark
  586.                 goto $endArgument
  587.                 markHilite
  588.                 message "modify argument?"
  589.             }
  590.         }
  591.     }
  592. }
  593. proc tabbing {} {alertnote "Not yet implemented."}
  594.  
  595. proc figure {} {
  596.     global useBoxMacro
  597.     global boxMacroName
  598.     if {$useBoxMacro} then {
  599.         set currentPos [getPos]
  600.         if {[insertEnvironment "figure" 0]} then {
  601.             insertText "\\centerline{\\$boxMacroName{•}}"
  602.         } else {
  603.             return
  604.         }
  605.     } else {
  606.         if {[wrapEnvironment "figure" 0]} then {
  607.             forwardChar
  608.             backwardChar
  609.             set currentPos [getPos]
  610.         } else {
  611.             set currentPos [getPos]
  612.             insertText "•"
  613.         }
  614.     }
  615.     carriageReturn
  616.     insertText "\\caption{•}"
  617.     carriageReturn
  618.     insertText "\\protect\\label{•}"
  619.     goto $currentPos
  620.     nextTabStop
  621. }
  622. proc table {} {
  623.     if {[wrapEnvironment "table" 0]} then {
  624.         forwardChar
  625.         backwardChar
  626.         set currentPos [getPos]
  627.     } else {
  628.         set currentPos [getPos]
  629.         insertText "•"
  630.     }
  631.     carriageReturn
  632.     insertText "\\caption{•}"
  633.     carriageReturn
  634.     insertText "\\protect\\label{•}"
  635.     goto $currentPos
  636.     nextTabStop
  637. }
  638. proc slide {} {
  639.     wrapEnvironment "slide" 1
  640.     message "enter colors"
  641. }
  642.  
  643. proc verbatim {} {wrapEnvironment "verbatim" 0}
  644. proc quote {} {wrapEnvironment "quote" 0}
  645. proc quotation {} {wrapEnvironment "quotation" 0}
  646. proc verse {} {wrapEnvironment "verse" 0}
  647.  
  648. proc index {} {alertnote "Not yet implemented."}
  649. proc bibliography {} {
  650.     catch {prompt "bibliography:  how many bibitems?" 3} numberItems
  651.     if {$numberItems != "cancel"} then {
  652.         if {[insertEnvironment "thebibliography" 1]} then {
  653.             set beginArgument [getPos]
  654.             insertText "99"
  655.             set endArgument [getPos]
  656.             nextTabStop
  657.             insertText "\\bibitem{•}"
  658.             carriageReturn
  659.             insertText "•"
  660.             for {set i 1} {$i < $numberItems} {incr i} {
  661.                 carriageReturn
  662.                 carriageReturn
  663.                 insertText "\\bibitem{•}"
  664.                 carriageReturn
  665.                 insertText "•"
  666.             }
  667.             goto $beginArgument
  668.             setMark
  669.             goto $endArgument
  670.             markHilite
  671.             message "modify argument?"
  672.         }
  673.     }
  674. }
  675.  
  676. proc general {} {
  677.     catch {prompt "What environment?" "center"} environmentName
  678.     if {$environmentName != "cancel"} {wrapEnvironment $environmentName 0}
  679. }
  680.  
  681. # Boxes:
  682. proc mbox {} {
  683.     if {[wrapObject "\\mbox{" "}•"]} then {
  684.         message "mbox set"
  685.     } else {
  686.         message "enter text"
  687.     }
  688. }
  689. proc fbox {} {alertnote "Not yet implemented."}
  690. proc parbox {} {alertnote "Not yet implemented."}
  691.  
  692. # Misc:
  693. proc ellipsis {} {insertObject "\\ldots"}
  694. proc sectionMark {} {insertObject "\\S"}
  695. proc paragraphMark {} {insertObject "\\P"}
  696. proc dagger {} {insertObject "\\dag"}
  697. proc dblDagger {} {insertObject "\\ddag"}
  698. proc copyright {} {insertObject "\\copyright"}
  699. proc pounds {} {insertObject "\\pounds"}
  700. proc {en-dash} {} {insertObject "--"}
  701. proc {em-dash} {} {insertObject "---"}
  702. proc texLogo {} {insertObject "\\TeX"}
  703. proc latexLogo {} {insertObject "\\LaTeX"}
  704. proc today {} {insertObject "\\today"}
  705.  
  706. proc quotes {} {
  707.     if {[wrapObject "`" "'•"]} then {
  708.         message "text quoted"
  709.     } else {
  710.         message "enter text"
  711.     }
  712. }
  713. proc dblQuotes {} {
  714.     if {[wrapObject "``" "''•"]} then {
  715.         message "text double quoted"
  716.     } else {
  717.         message "enter text"
  718.     }
  719. }
  720. proc note {} {
  721.     if {[wrapObject "\\marginpar{" "}•"]} then {
  722.         message "marginal note set"
  723.     } else {
  724.         message "enter marginal note"
  725.     }
  726. }
  727. proc footnote {} {
  728.     if {[wrapObject "\\footnote{" "}•"]} then {
  729.         message "footnote set"
  730.     } else {
  731.         message "enter footnote"
  732.     }
  733. }
  734. proc label {} {
  735.     if {[wrapObject "\\label{" "}•"]} then {
  736.         message "label defined"
  737.     } else {
  738.         message "enter label"
  739.     }
  740. }
  741. proc crossRef {} { 
  742.     if {[wrapObject "\\ref{" "}•"]} then {
  743.         message "cross-reference made"
  744.     } else {
  745.         message "enter cross-reference"
  746.     }
  747. }
  748. proc pageRef {} { 
  749.     if {[wrapObject "\\pageref{" "}•"]} then {
  750.         message "page reference made"
  751.     } else {
  752.         message "enter page reference"
  753.     }
  754. }
  755. proc citation {} {
  756.     if {[wrapObject "\\cite{" "}•"]} then {
  757.         message "citation made"
  758.     } else {
  759.         message "enter citation"
  760.     }
  761. }
  762. proc item {} {insertObject "\\item"}
  763. proc bibitem {} {
  764.     if {[wrapObject "\\bibitem{" "}•"]} then {
  765.         message "bibitem set"
  766.     } else {
  767.         message "enter bibitem"
  768.     }
  769. }
  770.  
  771.  
  772. #############################################################################
  773. # Math Mode Macros.
  774. #
  775. #############################################################################
  776.  
  777. # Modes:
  778. proc texMath {} {
  779.     if {[wrapObject "$" "$•"]} then {
  780.         message "formula set"
  781.     } else {
  782.         message "enter formula"
  783.     }
  784. }
  785. proc texDisplaymath {} {
  786.     if {[wrapObject "$$" "$$•"]} then {
  787.         message "displayed formula set"
  788.     } else {
  789.         message "enter displayed formula"
  790.     }
  791. }
  792. proc latexMath {} {
  793.     if {[wrapObject "\\( " " \\)•"]} then {
  794.         message "formula set"
  795.     } else {
  796.         message "enter formula"
  797.     }
  798. }
  799. proc latexDisplaymath {} {
  800.     if {[wrapObject "\\\[ " " \\\]•"]} then {
  801.         message "displayed formula set"
  802.     } else {
  803.         message "enter displayed formula"
  804.     }
  805. }
  806.  
  807. # Environments:
  808. proc math {} {wrapEnvironment "math" 0}
  809. proc displaymath {} {wrapEnvironment "displaymath" 0}
  810. proc equation {} {
  811.     if {[wrapEnvironment "equation" 0]} then {
  812.         forwardChar
  813.         backwardChar
  814.         set currentPos [getPos]
  815.     } else {
  816.         set currentPos [getPos]
  817.         insertText "•"
  818.     }
  819.     carriageReturn
  820.     insertText "\\label{•}"
  821.     goto $currentPos
  822.     nextTabStop
  823. }
  824. proc myArray {} {
  825.     catch {prompt "array:  how many rows?" 3} numberRows
  826.     if {$numberRows != "cancel"} then {
  827.         catch {prompt "array:  how many columns?" 3} numberCols
  828.         if {$numberCols != "cancel"} then {
  829.             if {[insertEnvironment "array" 1]} then {
  830.                 set beginArgument [getPos]
  831.                 for {set j 1} {$j <= $numberCols} {incr j} {
  832.                     insertText "c"
  833.                 }
  834.                 set endArgument [getPos]
  835.                 nextTabStop
  836.                 for {set i 1} {$i < $numberRows} {incr i} {
  837.                     insertRow $numberCols
  838.                     insertText "  \\\\"
  839.                     carriageReturn
  840.                 }
  841.                 insertRow $numberCols
  842.                 goto $beginArgument
  843.                 setMark
  844.                 goto $endArgument
  845.                 markHilite
  846.                 message "modify argument?"
  847.             }
  848.         }
  849.     }
  850. }
  851. proc eqnarray {} {
  852.     catch {prompt "eqnarray:  how many rows?" 3} numberRows
  853.     if {$numberRows != "cancel"} then {
  854.         set currentPos [getPos]
  855.         if {[insertEnvironment "eqnarray" 0]} then {
  856.             for {set i 1} {$i < $numberRows} {incr i} {
  857.                 insertRow 3
  858.                 carriageReturn
  859.                 insertText "\\label{•} \\\\"
  860.                 carriageReturn
  861.             }
  862.             insertRow 3
  863.             carriageReturn
  864.             insertText "\\label{•}"
  865.             goto $currentPos
  866.             nextTabStop
  867.         }
  868.     }
  869. }
  870. proc eqnarrayStar {} {
  871.     catch {prompt "eqnarray*:  how many rows?" 3} numberRows
  872.     if {$numberRows != "cancel"} then {
  873.         set currentPos [getPos]
  874.         if {[insertEnvironment "eqnarray*" 0]} then {
  875.             for {set i 1} {$i < $numberRows} {incr i} {
  876.                 insertRow 3
  877.                 insertText "  \\\\"
  878.                 carriageReturn
  879.             }
  880.             insertRow 3
  881.             goto $currentPos
  882.             nextTabStop
  883.         }
  884.     }
  885. }
  886.  
  887. # Formulas:
  888. proc subscript {} {
  889.     if {[wrapObject "_{" "}•"]} then {
  890.         message "subscript set"
  891.     } else {
  892.         message "enter subscript"
  893.     }
  894. }
  895. proc superscript {} {
  896.     if {[wrapObject "^{" "}•"]} then {
  897.         message "superscript set"
  898.     } else {
  899.         message "enter superscript"
  900.     }
  901. }
  902. proc fraction {} {
  903.     set currentPos [getPos]
  904.     if {[isSelection]} then {
  905.         set selection [getSelect]
  906.         set args [split $selection /]
  907.         set len [llength $args]
  908.         deleteText $currentPos [selEnd]
  909.         if {$len == 1} then {
  910.             # maybe the selection should be deleted in this case?
  911.             insertText "\\frac{" $selection "}{•}•"
  912.             goto $currentPos
  913.             nextTabStop
  914.             message "enter denominator"
  915.         } else {
  916.             set firstArg [lindex $args 0]
  917.             set restArgs [lrange $args 1 [expr $len-1]]
  918.             insertText "\\frac{" $firstArg "}{" [join $restArgs /] "}"
  919.             if {$len > 2} {message "beware of multiple /"}
  920.         }
  921.     } else {
  922.         insertText "\\frac{•}{•}•"
  923.         goto $currentPos
  924.         nextTabStop
  925.         message "enter numerator"
  926.     }
  927. }
  928. proc squareRoot {} {
  929.     if {[wrapObject "\\sqrt{" "}•"]} then {
  930.         message "square root set"
  931.     } else {
  932.         message "enter formula"
  933.     }
  934. }
  935. proc nthRoot {} {
  936.     if {[wrapObject "\\sqrt\[•\]{" "}•"]} then {
  937.         message "enter root"
  938.     } else {
  939.         message "enter root, then formula"
  940.     }
  941. }
  942. proc oneParameter {} {
  943.     catch {prompt "Command name?" "sqrt"} commandName
  944.     if {$commandName != "cancel"} {wrapObject "\\$commandName{" "}•"}
  945. }
  946. proc twoParameters {} {
  947.     catch {prompt "Command name?" "frac"} commandName
  948.     if {$commandName != "cancel"} then {
  949.         set currentPos [getPos]
  950.         if {[insertObject "\\$commandName{•}{•}•"]} then {
  951.             goto $currentPos
  952.             nextTabStop
  953.         }
  954.     }
  955. }
  956.  
  957. # Greek:
  958. proc alpha {} {insertObject "\\alpha"}
  959. proc beta {} {insertObject "\\beta"}
  960. proc gamma {} {insertObject "\\gamma"}
  961. proc delta {} {insertObject "\\delta"}
  962. proc epsilon {} {insertObject "\\epsilon"}
  963. proc zeta {} {insertObject "\\zeta"}
  964. proc eta {} {insertObject "\\eta"}
  965. proc theta {} {insertObject "\\theta"}
  966. proc iota {} {insertObject "\\iota"}
  967. proc kappa {} {insertObject "\\kappa"}
  968. proc lambda {} {insertObject "\\lambda"}
  969. proc mu {} {insertObject "\\mu"}
  970. proc nu {} {insertObject "\\nu"}
  971. proc xi {} {insertObject "\\xi"}
  972. proc pi {} {insertObject "\\pi"}
  973. proc rho {} {insertObject "\\rho"}
  974. proc sigma {} {insertObject "\\sigma"}
  975. proc tau {} {insertObject "\\tau"}
  976. proc upsilon {} {insertObject "\\upsilon"}
  977. proc phi {} {insertObject "\\phi"}
  978. proc chi {} {insertObject "\\chi"}
  979. proc psi {} {insertObject "\\psi"}
  980. proc omega {} {insertObject "\\omega"}
  981.  
  982. proc capGamma {} {insertObject "\\Gamma"}
  983. proc capDelta {} {insertObject "\\Delta"}
  984. proc capTheta {} {insertObject "\\Theta"}
  985. proc capLambda {} {insertObject "\\Lambda"}
  986. proc capXi {} {insertObject "\\Xi"}
  987. proc capPi {} {insertObject "\\Pi"}
  988. proc capSigma {} {insertObject "\\Sigma"}
  989. proc capUpsilon {} {insertObject "\\Upsilon"}
  990. proc capPhi {} {insertObject "\\Phi"}
  991. proc capPsi {} {insertObject "\\Psi"}
  992. proc capOmega {} {insertObject "\\Omega"}
  993.  
  994. proc varEpsilon {} {insertObject "\\varepsilon"}
  995. proc varTheta {} {insertObject "\\vartheta"}
  996. proc varPi {} {insertObject "\\varpi"}
  997. proc varRho {} {insertObject "\\varrho"}
  998. proc varSigma {} {insertObject "\\varsigma"}
  999. proc varPhi {} {insertObject "\\varphi"}
  1000.  
  1001. # Binary Ops:
  1002. proc plusOrMinus {} {insertObject "\\pm"}
  1003. proc minusOrPlus {} {insertObject "\\mp"}
  1004. proc multiply {} {insertObject "\\times"}
  1005. proc divide {} {insertObject "\\div"}
  1006. proc asterisk {} {insertObject "\\ast"}
  1007. proc star {} {insertObject "\\star"}
  1008. proc circle {} {insertObject "\\circ"}
  1009. proc bigCircle {} {insertObject "\\bigcirc"}
  1010. proc bullet {} {insertObject "\\bullet"}
  1011. proc centerDot {} {insertObject "\\cdot"}
  1012. proc intersection {} {insertObject "\\cap"}
  1013. proc union {} {insertObject "\\cup"}
  1014. proc logicalAnd {} {insertObject "\\wedge"}
  1015. proc logicalOr {} {insertObject "\\vee"}
  1016. proc setMinus {} {insertObject "\\setminus"}
  1017.  
  1018. # Relations:
  1019. proc notEqual {} {insertObject "\\neq"}
  1020. proc lessOrEqual {} {insertObject "\\leq"}
  1021. proc greaterOrEqual {} {insertObject "\\geq"}
  1022. proc subset {} {insertObject "\\subset"}
  1023. proc superset {} {insertObject "\\supset"}
  1024. proc subsetOrEqual {} {insertObject "\\subseteq"}
  1025. proc supersetOrEqual {} {insertObject "\\supseteq"}
  1026. proc elementOf {} {insertObject "\\in"}
  1027. proc equivalent {} {insertObject "\\equiv"}
  1028. proc similar {} {insertObject "\\sim"}
  1029. proc similarEqual {} {insertObject "\\simeq"}
  1030. proc dotEqual {} {insertObject "\\doteq"}
  1031. proc approximate {} {insertObject "\\approx"}
  1032. proc congruent {} {insertObject "\\cong"}
  1033.  
  1034. # Large Ops:
  1035. proc insertLargeOp {commandName} {
  1036.     set currentPos [getPos]
  1037.     insertText "\\$commandName"
  1038.     insertText "_{•}^{•}•"
  1039.     goto $currentPos
  1040.     nextTabStop
  1041. }
  1042. proc sum {} {insertLargeOp "sum"}
  1043. proc product {} {insertLargeOp "prod"}
  1044. proc integral {} {insertLargeOp "int"}
  1045. proc bigUnion {} {insertLargeOp "bigcup"}
  1046. proc bigIntersection {} {insertLargeOp "bigcap"}
  1047. proc bigAnd {} {insertLargeOp "bigwedge"}
  1048. proc bigOr {} {insertLargeOp "bigvee"}
  1049.  
  1050. # Arrows:
  1051. proc mapsTo {} {insertObject "\\mapsto"}
  1052. proc leftArrow {} {insertObject "\\leftarrow"}
  1053. proc rightArrow {} {insertObject "\\rightarrow"}
  1054. proc {left-rightArrow} {} {insertObject "\\leftrightarrow"}
  1055. proc dblLeftArrow {} {insertObject "\\Leftarrow"}
  1056. proc dblRightArrow {} {insertObject "\\Rightarrow"}
  1057. proc {dblLeft-rightArrow} {} {insertObject "\\Leftrightarrow"}
  1058.  
  1059. # Dots:
  1060. proc centerDots {} {insertObject "\\cdots"}
  1061. proc verticalDots {} {insertObject "\\vdots"}
  1062. proc diagonalDots {} {insertObject "\\ddots"}
  1063.  
  1064. # Symbols:
  1065. proc aleph {} {insertObject "\\aleph"}
  1066. proc emptySet {} {insertObject "\\emptyset"}
  1067. proc negation {} {insertObject "\\neg"}
  1068. proc forAll {} {insertObject "\\forall"}
  1069. proc exists {} {insertObject "\\exists"}
  1070. proc scriptL {} {insertObject "\\ell"}
  1071. proc nabla {} {insertObject "\\nabla"}
  1072. proc partial {} {insertObject "\\partial"}
  1073. proc infinity {} {insertObject "\\infty"}
  1074. proc backslash {} {insertObject "\\backslash"}
  1075. proc angle {} {insertObject "\\angle"}
  1076. proc box {} {insertObject "\\Box"}
  1077. proc diamond {} {insertObject "\\Diamond"}
  1078. proc triangle {} {insertObject "\\triangle"}
  1079.  
  1080. # Functions:  not yet implemented.
  1081.  
  1082. # Delimiters:
  1083. proc parentheses {} {
  1084.     if {[wrapObject "(" ")•"]} then {
  1085.         message "formula delimited"
  1086.     } else {
  1087.         message "enter formula"
  1088.     }
  1089. }
  1090. proc brackets {} {
  1091.     if {[wrapObject "\[" "\]•"]} then {
  1092.         message "formula delimited"
  1093.     } else {
  1094.         message "enter formula"
  1095.     }
  1096. }
  1097. proc braces {} {
  1098.     if {[wrapObject "\\\{" "\\\}•"]} then {
  1099.         message "formula delimited"
  1100.     } else {
  1101.         message "enter formula"
  1102.     }
  1103. }
  1104. proc absoluteValue {} {
  1105.     if {[wrapObject "|" "|•"]} then {
  1106.         message "formula delimited"
  1107.     } else {
  1108.         message "enter formula"
  1109.     }
  1110. }
  1111. proc otherDelims {} {
  1112.     catch {prompt "Choose delimiters:" "parentheses" "" "parentheses" "brackets" "braces" "angle brackets" "vertical bars" "double bars" "ceiling" "floor"} delimType
  1113.     if {$delimType != "cancel"} then {
  1114.         case $delimType in {
  1115.             "parentheses" {
  1116.                 set leftDelim "("
  1117.                 set rightDelim ")"
  1118.             }
  1119.             "brackets" {
  1120.                 set leftDelim "\["
  1121.                 set rightDelim "\]"
  1122.             }
  1123.             "braces" {
  1124.                 set leftDelim "\\\{"
  1125.                 set rightDelim "\\\}"
  1126.             }
  1127.             "{angle brackets}" {
  1128.                 set leftDelim "\\langle"
  1129.                 set rightDelim "\\rangle"
  1130.             }
  1131.             "{vertical bars}" {
  1132.                 set leftDelim "|"
  1133.                 set rightDelim "|"
  1134.             }
  1135.             "{double bars}" {
  1136.                 set leftDelim "\\|"
  1137.                 set rightDelim "\\|"
  1138.             }
  1139.             "ceiling" {
  1140.                 set leftDelim "\\lceil"
  1141.                 set rightDelim "\\rceil"
  1142.             }
  1143.             "floor" {
  1144.                 set leftDelim "\\lfloor"
  1145.                 set rightDelim "\\rfloor"
  1146.             }
  1147.             default {
  1148.                 alertnote "\"$delimType\" not recognized"
  1149.                 return
  1150.             }
  1151.         }
  1152.         if {[wrapObject "$leftDelim" "$rightDelim•"]} then {
  1153.             message "formula delimited"
  1154.         } else {
  1155.             message "enter formula"
  1156.         }
  1157.     }
  1158. }
  1159.  
  1160. proc {half-openInterval} {} {
  1161.     if {[wrapObject "(" "\]•"]} then {
  1162.         message "formula delimited"
  1163.     } else {
  1164.         message "enter formula"
  1165.     }
  1166. }
  1167. proc {half-closedInterval} {} {
  1168.     if {[wrapObject "\[" ")•"]} then {
  1169.         message "formula delimited"
  1170.     } else {
  1171.         message "enter formula"
  1172.     }
  1173. }
  1174.  
  1175. proc bigParentheses {} {
  1176.     if {[wrapObject "\\left(" "\\right)•"]} then {
  1177.         message "formula delimited"
  1178.     } else {
  1179.         message "enter formula"
  1180.     }
  1181. }
  1182. proc bigBrackets {} {
  1183.     if {[wrapObject "\\left\[" "\\right\]•"]} then {
  1184.         message "formula delimited"
  1185.     } else {
  1186.         message "enter formula"
  1187.     }
  1188. }
  1189. proc bigBraces {} {
  1190.     if {[wrapObject "\\left\\\{" "\\right\\\}•"]} then {
  1191.         message "formula delimited"
  1192.     } else {
  1193.         message "enter formula"
  1194.     }
  1195. }
  1196. proc bigAbsoluteValue {} {
  1197.     if {[wrapObject "\\left|" "\\right|•"]} then {
  1198.         message "formula delimited"
  1199.     } else {
  1200.         message "enter formula"
  1201.     }
  1202. }
  1203. proc otherBigDelims {} {
  1204.     catch {prompt "Choose delimiters:" "parentheses" "" "parentheses" "brackets" \
  1205.                 "braces" "angle brackets" "vertical bars" "double bars" \
  1206.                 "ceiling" "floor"} delimType
  1207.     if {$delimType != "cancel"} then {
  1208.         case $delimType in {
  1209.             "parentheses" {
  1210.                 set leftDelim "("
  1211.                 set rightDelim ")"
  1212.             }
  1213.             "brackets" {
  1214.                 set leftDelim "\["
  1215.                 set rightDelim "\]"
  1216.             }
  1217.             "braces" {
  1218.                 set leftDelim "\\\{"
  1219.                 set rightDelim "\\\}"
  1220.             }
  1221.             "{angle brackets}" {
  1222.                 set leftDelim "\\langle"
  1223.                 set rightDelim "\\rangle"
  1224.             }
  1225.             "{vertical bars}" {
  1226.                 set leftDelim "|"
  1227.                 set rightDelim "|"
  1228.             }
  1229.             "{double bars}" {
  1230.                 set leftDelim "\\|"
  1231.                 set rightDelim "\\|"
  1232.             }
  1233.             "ceiling" {
  1234.                 set leftDelim "\\lceil"
  1235.                 set rightDelim "\\rceil"
  1236.             }
  1237.             "floor" {
  1238.                 set leftDelim "\\lfloor"
  1239.                 set rightDelim "\\rfloor"
  1240.             }
  1241.             default {
  1242.                 alertnote "\"$delimType\" not recognized"
  1243.                 return
  1244.             }
  1245.         }
  1246.         if {[wrapObject "\\left$leftDelim" "\\right$rightDelim•"]} then {
  1247.             message "formula delimited"
  1248.         } else {
  1249.             message "enter formula"
  1250.         }
  1251.     }
  1252. }
  1253.  
  1254. proc bigLeftBrace {} {
  1255.     if {[wrapObject "\\left\\\{" "\\right.•"]} then {
  1256.         message "formula delimited"
  1257.     } else {
  1258.         message "enter formula"
  1259.     }
  1260. }
  1261. proc otherMixedBigDelims {} {
  1262.     catch {prompt "Choose left delimiter:" "parenthesis" "" "parenthesis" "bracket" \
  1263.              "brace" "angle bracket" "vertical bar" "double bar" "ceiling" "floor"  \
  1264.              "slash" "backslash" "none"} delimType
  1265.     if {$delimType != "cancel"} then {
  1266.         case $delimType in {
  1267.             "parenthesis" {set leftDelim "("}
  1268.             "bracket" {set leftDelim "\["}
  1269.             "brace" {set leftDelim "\\\{"}
  1270.             "{angle bracket}" {set leftDelim "\\langle"}
  1271.             "{vertical bar}" {set leftDelim "|"}
  1272.             "{double bar}" {set leftDelim "\\|"}
  1273.             "ceiling" {set leftDelim "\\lceil"}
  1274.             "floor" {set leftDelim "\\lfloor"}
  1275.             "slash" {set leftDelim "/"}
  1276.             "backslash" {set leftDelim "\\backslash"}
  1277.             "none" {set leftDelim "."}
  1278.             default {
  1279.                 alertnote "\"$delimType\" not recognized"
  1280.                 return
  1281.             }
  1282.         }
  1283.         catch {prompt "Choose right delimiter:" "parenthesis" "" "parenthesis" "bracket" \
  1284.                 "brace" "angle bracket" "vertical bar" "double bar" "ceiling" "floor" \
  1285.                 "slash" "backslash" "none"} delimType
  1286.         if {$delimType != "cancel"} then {
  1287.             case $delimType in {
  1288.                 "parenthesis" {set rightDelim ")"}
  1289.                 "bracket" {set rightDelim "\]"}
  1290.                 "brace" {set rightDelim "\\\}"}
  1291.                 "{angle bracket}" {set rightDelim "\\rangle"}
  1292.                 "{vertical bar}" {set rightDelim "|"}
  1293.                 "{double bar}" {set rightDelim "\\|"}
  1294.                 "ceiling" {set rightDelim "\\rceil"}
  1295.                 "floor" {set rightDelim "\\rfloor"}
  1296.                 "slash" {set rightDelim "/"}
  1297.                 "backslash" {set rightDelim "\\backslash"}
  1298.                 "none" {set rightDelim "."}
  1299.                 default {
  1300.                     alertnote "\"$delimType\" not recognized"
  1301.                     return
  1302.                 }
  1303.             }
  1304.             if {[wrapObject "\\left$leftDelim" "\\right$rightDelim•"]} then {
  1305.                 message "formula delimited"
  1306.             } else {
  1307.                 message "enter formula"
  1308.             }
  1309.         }
  1310.     }
  1311. }
  1312.  
  1313. # Accents:
  1314. proc hat {} {
  1315.     if {[isSelection] > 1} then {
  1316.         beep
  1317.         alertnote "Warning: only a single character may be accented!"
  1318.     }
  1319.     if {[wrapObject "\\hat{" "}•"]} then {
  1320.         message "accent set"
  1321.     } else {
  1322.         message "enter one character"
  1323.     }
  1324. }
  1325. proc check {} {
  1326.     if {[isSelection] > 1} then {
  1327.         beep
  1328.         alertnote "Warning: only a single character may be accented!"
  1329.     }
  1330.     if {[wrapObject "\\check{" "}•"]} then {
  1331.         message "accent set"
  1332.     } else {
  1333.         message "enter one character"
  1334.     }
  1335. }
  1336. proc breve {} {
  1337.     if {[isSelection] > 1} then {
  1338.         beep
  1339.         alertnote "Warning: only a single character may be accented!"
  1340.     }
  1341.     if {[wrapObject "\\breve{" "}•"]} then {
  1342.         message "accent set"
  1343.     } else {
  1344.         message "enter one character"
  1345.     }
  1346. }
  1347. proc acuteAccent {} {
  1348.     if {[isSelection] > 1} then {
  1349.         beep
  1350.         alertnote "Warning: only a single character may be accented!"
  1351.     }
  1352.     if {[wrapObject "\\acute{" "}•"]} then {
  1353.         message "accent set"
  1354.     } else {
  1355.         message "enter one character"
  1356.     }
  1357. }
  1358. proc graveAccent {} {
  1359.     if {[isSelection] > 1} then {
  1360.         beep
  1361.         alertnote "Warning: only a single character may be accented!"
  1362.     }
  1363.     if {[wrapObject "\\grave{" "}•"]} then {
  1364.         message "accent set"
  1365.     } else {
  1366.         message "enter one character"
  1367.     }
  1368. }
  1369. proc tilde {} {
  1370.     if {[isSelection] > 1} then {
  1371.         beep
  1372.         alertnote "Warning: only a single character may be accented!"
  1373.     }
  1374.     if {[wrapObject "\\tilde{" "}•"]} then {
  1375.         message "accent set"
  1376.     } else {
  1377.         message "enter one character"
  1378.     }
  1379. }
  1380. proc bar {} {
  1381.     if {[isSelection] > 1} then {
  1382.         beep
  1383.         alertnote "Warning: only a single character may be accented!"
  1384.     }
  1385.     if {[wrapObject "\\bar{" "}•"]} then {
  1386.         message "accent set"
  1387.     } else {
  1388.         message "enter one character"
  1389.     }
  1390. }
  1391. proc vector {} {
  1392.     if {[isSelection] > 1} then {
  1393.         beep
  1394.         alertnote "Warning: only a single character may be accented!"
  1395.     }
  1396.     if {[wrapObject "\\vec{" "}•"]} then {
  1397.         message "accent set"
  1398.     } else {
  1399.         message "enter one character"
  1400.     }
  1401. }
  1402. proc dot {} {
  1403.     if {[isSelection] > 1} then {
  1404.         beep
  1405.         alertnote "Warning: only a single character may be accented!"
  1406.     }
  1407.     if {[wrapObject "\\dot{" "}•"]} then {
  1408.         message "accent set"
  1409.     } else {
  1410.         message "enter one character"
  1411.     }
  1412. }
  1413. proc dblDot {} {
  1414.     if {[isSelection] > 1} then {
  1415.         beep
  1416.         alertnote "Warning: only a single character may be accented!"
  1417.     }
  1418.     if {[wrapObject "\\ddot{" "}•"]} then {
  1419.         message "accent set"
  1420.     } else {
  1421.         message "enter one character"
  1422.     }
  1423. }
  1424.  
  1425. proc wideHat {} {
  1426.     if {[isSelection] > 3} then {
  1427.         beep
  1428.         alertnote "Warning: only a few characters may be accented!"
  1429.     }
  1430.     if {[wrapObject "\\widehat{" "}•"]} then {
  1431.         message "accent set"
  1432.     } else {
  1433.         message "enter a few characters"
  1434.     }
  1435. }
  1436. proc wideTilde {} {
  1437.     if {[isSelection] > 3} then {
  1438.         beep
  1439.         alertnote "Warning: only a few characters may be accented!"
  1440.     }
  1441.     if {[wrapObject "\\widetilde{" "}•"]} then {
  1442.         message "accent set"
  1443.     } else {
  1444.         message "enter a few characters"
  1445.     }
  1446. }
  1447.  
  1448. proc dotlessI {} {insertObject "\\imath"}
  1449. proc dotlessJ {} {insertObject "\\jmath"}
  1450.  
  1451. # Grouping:
  1452. proc underline {} {
  1453.     if {[wrapObject "\\underline{" "}•"]} then {
  1454.         message "selection underlined"
  1455.     } else {
  1456.         message "enter text"
  1457.     }
  1458. }
  1459. proc overline {} {
  1460.     if {[wrapObject "\\overline{" "}•"]} then {
  1461.         message "selection overlined"
  1462.     } else {
  1463.         message "enter text"
  1464.     }
  1465. }
  1466. proc underbrace {} {
  1467.     if {[wrapObject "\\underbrace{" "}•"]} then {
  1468.         message "selection underbraced"
  1469.     } else {
  1470.         message "enter text"
  1471.     }
  1472. }
  1473. proc overbrace {} {
  1474.     if {[wrapObject "\\overbrace{" "}•"]} then {
  1475.         message "selection overbraced"
  1476.     } else {
  1477.         message "enter text"
  1478.     }
  1479. }
  1480. proc stack {} {
  1481.     set currentPos [getPos]
  1482.     if {[insertObject "\\stackrel{•}{•}•"]} then {
  1483.         goto $currentPos
  1484.         nextTabStop
  1485.         message "1st arg scriptstyle"
  1486.     }
  1487. }
  1488.  
  1489. # Spacing:
  1490. proc thin {} {insertObject "\\,"}
  1491. proc negThin {} {insertObject "\\!"}
  1492. proc medium {} {insertObject "\\:"}
  1493. proc thick {} {insertObject "\\;"}
  1494. proc quad {} {insertObject "\\quad"}
  1495. proc dblQuad {} {insertObject "\\qquad"}
  1496.  
  1497. # Math Style:
  1498. proc mathItalic {} {
  1499.     if {[wrapObject "{\\mit " "}•"]} then {
  1500.         message "math italics set"
  1501.     } else {
  1502.         message "enter italicized text"
  1503.     }
  1504. }
  1505. proc calligraphic {} {
  1506.     # Check for upper-case arguments only:
  1507.     if {[wrapObject "{\\cal " "}•"]} then {
  1508.         message "calligraphics set"
  1509.     } else {
  1510.         message "enter text"
  1511.     }
  1512. }
  1513. proc fraktur {} {
  1514.     alertnote "Not yet implemented."
  1515. }
  1516. proc script {} {
  1517.     alertnote "Not yet implemented."
  1518. }
  1519. proc blackboardBold {} {
  1520.     alertnote "Not yet implemented."
  1521. }
  1522. proc displayStyle {} {
  1523.     if {[wrapObject "{\\displaystyle " "}•"]} then {
  1524.         message "displaystyle set"
  1525.     } else {
  1526.         message "enter displaystyle text"
  1527.     }
  1528. }
  1529. proc textStyle {} {
  1530.     if {[wrapObject "{\\textstyle " "}•"]} then {
  1531.         message "textstyle set"
  1532.     } else {
  1533.         message "enter textstyle text"
  1534.     }
  1535. }
  1536. proc scriptStyle {} {
  1537.     if {[wrapObject "{\\scriptstyle " "}•"]} then {
  1538.         message "scriptstyle set"
  1539.     } else {
  1540.         message "enter scriptstyle text"
  1541.     }
  1542. }
  1543. proc scriptscriptStyle {} {
  1544.     if {[wrapObject "{\\scriptscriptstyle " "}•"]} then {
  1545.         message "scriptscriptstyle set"
  1546.     } else {
  1547.         message "enter scriptscriptstyle text"
  1548.     }
  1549. }
  1550.  
  1551.  
  1552. #############################################################################
  1553. #
  1554. # LaTeX Menu Definition.
  1555. #
  1556. #############################################################################
  1557.  
  1558. proc interpretMenuItem {menu item} {
  1559.     switch $item {
  1560.         "list" {set func "myList"}
  1561.         "array" {set func "myArray"}
  1562.         "eqnarray\*" {set func "eqnarrayStar"}
  1563.         default {set func $item}
  1564.     }
  1565.     eval $func
  1566. }
  1567.  
  1568. # LaTeX mode
  1569. proc setTexMode {} {
  1570.     global texMenu
  1571.     changeMode "TeX"
  1572.     uplevel #0 {    
  1573.         set wordBreakPreface {[^a-zA-Z0-9]}
  1574.         set wordBreak {[a-zA-Z0-9]+}
  1575.         set elecLBrace 0
  1576.         set elecRBrace 0
  1577.         set electricSemi 0
  1578.         set wordWrap 1
  1579.         set prefixString "% "
  1580.         set suffixString { \\\\}
  1581.         set sortedIsDefault 0
  1582.         set funcExpr {^\\(sub)*section\*?{([^{}]*)}}
  1583. #        set funcExpr {^\\(sub)*section\*?{(.*)}$}
  1584.         set funcPar 2
  1585.         set savedIsMeta $optionIsMeta
  1586. #    Uncomment next line to use option key in Tex bindings.
  1587. #        set optionIsMeta 0
  1588. #    Next is a call to a random proc in the latex file to make sure
  1589. #    is it auto-loaded.
  1590.         isSelection
  1591.     }
  1592. }
  1593.  
  1594. #================================================================================
  1595. proc latex {} {
  1596.     global latexPath
  1597.     set sig ""
  1598.     catch {string trim [lindex [getfinfo $latexPath] 1] '} sig
  1599.     set name [checkRunning latex $sig latexPath]
  1600.     if {![string length $name]} return
  1601.     switchTo $name
  1602. }
  1603.  
  1604. proc commentLine {} {
  1605.     beginningOfLine
  1606.     insertText "% "
  1607.     nextLine
  1608.     beginningOfLine
  1609. }
  1610.  
  1611.  
  1612. proc texMarkFile {} {
  1613.     global mpos
  1614.     
  1615.     set end [maxPos]
  1616.     set pos 0
  1617.     set l {}
  1618.  
  1619.     # Remove all previous marks in this file
  1620.     if {[string length [search -f 1 -r 0 -n  {\chapter} 0]]} {
  1621.         set expr {^\\(chapter|section)}
  1622.     } else {
  1623.         set expr {^\\(sub)?section}
  1624.     }
  1625.  
  1626.     while {![catch {search -f 1 -r 1 -m 0 -i 0 $expr $pos} res]} {
  1627.         set start [lindex $res 0]
  1628.         set end [nextLineStart $start]
  1629.         set text [getText $start $end]
  1630.         if {[regexp {\{(.*)\}} $text dummy mtch]} {
  1631.             set lab ""
  1632.             if {[regexp {(sub)*section} $text title]} {
  1633.                 set lab "   "
  1634.                 set title [string range $title 0 [expr [string length $title] - 7]]
  1635.                 append lab [string range "               " 0 [string length $title]]
  1636.             }
  1637.             append lab $mtch
  1638.             setNamedMark $lab [lineStart [expr $start - 1]] $start $start
  1639.         }
  1640.         set pos $end
  1641.     }
  1642. }
  1643.     
  1644. # Open file in same directory, expect name w/o extension selected.
  1645. proc openInputFile {} {
  1646.     set text [getSelect].tex
  1647.     if {[string length $text] < 5} { beep; return }
  1648.     foreach f [winNames] {
  1649.         if {$f == $text} {
  1650.             bringToFront $f
  1651.             return
  1652.         }
  1653.     }
  1654.     edit [file dirname [lindex [winNames -f] 0]]:$text
  1655. }
  1656.  
  1657.  
  1658. menu -n $texMenu  {
  1659.     "/-latex"
  1660.     "openInputFile"
  1661.     "(-"
  1662.     {menu -n Documents -p interpretMenuItem {
  1663.         "letter"
  1664.         "article"
  1665.         "report"
  1666.         "book"
  1667.         "(-"
  1668.         "custom…"}
  1669.     }
  1670.     
  1671.     {menu -n Sectioning -p interpretMenuItem {
  1672.         "part"
  1673.         "chapter"
  1674.         "section"
  1675.         "subsection"
  1676.         "subsubsection"
  1677.         "paragraph"
  1678.         "subparagraph"}
  1679.     }
  1680.     
  1681.     {menu -n (Definitions -p interpretMenuItem {
  1682.         "list…"
  1683.         "(-"
  1684.         "newcommand…"
  1685.         "newenvironment…"
  1686.         "newtheorem…"
  1687.         "(-"
  1688.         "renewcommand…"
  1689.         "renewenvironment…"}
  1690.     }
  1691.     
  1692.     "(-"
  1693.     
  1694.     {menu -n TextStyle -p interpretMenuItem {
  1695.         "roman"
  1696.         "bold"
  1697.         "italic"
  1698.         "emphatic"
  1699.         "slanted"
  1700.         "sansSerif"
  1701.         "smallCaps"
  1702.         "typewriter"}
  1703.     }
  1704.     
  1705.     {menu -n TextSize -p interpretMenuItem {
  1706.         "tiny"
  1707.         "smallest"
  1708.         "smaller"
  1709.         "small"
  1710.         "normal"
  1711.         "large"
  1712.         "larger"
  1713.         "largest"
  1714.         "huge"
  1715.         "gigantic"}
  1716.     }
  1717.     
  1718.     {menu -n (International -p interpretMenuItem {
  1719.         }
  1720.     }
  1721.     
  1722.     {menu -n Environments -p interpretMenuItem {
  1723.         "enumerate…"
  1724.         "itemize…"
  1725.         "description…"
  1726.         "(-"
  1727.         "tabular…"
  1728.         "(tabbing"
  1729.         "(-"
  1730.         "figure"
  1731.         "table"
  1732.         "slide"
  1733.         "(-"
  1734.         "verbatim"
  1735.         "quote"
  1736.         "quotation"
  1737.         "verse"
  1738.         "(-"
  1739.         "(index…"
  1740.         "bibliography…"
  1741.         "(-"
  1742.         "general…"}
  1743.     }
  1744.     
  1745.     {menu -n Boxes -p interpretMenuItem {
  1746.         "mbox"
  1747.         "(fbox"
  1748.         "(parbox"}
  1749.     }
  1750.     
  1751.     {menu -n Miscellaneous -p interpretMenuItem {
  1752.         "ellipsis"
  1753.         "sectionMark"
  1754.         "paragraphMark"
  1755.         "dagger"
  1756.         "dblDagger"
  1757.         "en-dash"
  1758.         "em-dash"
  1759.         "texLogo"
  1760.         "latexLogo"
  1761.         "copyright"
  1762.         "pounds"
  1763.         "today"
  1764.         "(-"
  1765.         "quotes"
  1766.         "dblQuotes"
  1767.         "(-"
  1768.         "note"
  1769.         "footnote"
  1770.         "(-"
  1771.         "label"
  1772.         "crossRef"
  1773.         "pageRef"
  1774.         "citation"
  1775.         "(-"
  1776.         "item"
  1777.         "bibitem"
  1778.         }
  1779.     }
  1780.     
  1781.     "(-"
  1782.     
  1783.     {menu -n mathModes -p interpretMenuItem {
  1784.         "texMath"
  1785.         "texDisplaymath"
  1786.         "(-"
  1787.         "latexMath"
  1788.         "latexDisplaymath"}
  1789.     }
  1790.     
  1791.     {menu -n mathEnvironments -p interpretMenuItem {
  1792.         "math"
  1793.         "displaymath"
  1794.         "equation"
  1795.         "(-"
  1796.         "array…"
  1797.         "eqnarray…"
  1798.         "eqnarray*…"
  1799.         "(-"
  1800.         "general…"}
  1801.     }
  1802.     
  1803.     {menu -n Formulas -p interpretMenuItem {
  1804.         "subscript"
  1805.         "superscript"
  1806.         "fraction"
  1807.         "squareRoot"
  1808.         "nthRoot"
  1809.         "(-"
  1810.         "oneParameter…"
  1811.         "twoParameters…"
  1812.         }
  1813.     }
  1814.     
  1815.     {menu -n Greek -p interpretMenuItem {
  1816.         "alpha"
  1817.         "beta"
  1818.         "gamma"
  1819.         "delta"
  1820.         "epsilon"
  1821.         "zeta"
  1822.         "eta"
  1823.         "theta"
  1824.         "iota"
  1825.         "kappa"
  1826.         "lambda"
  1827.         "mu"
  1828.         "nu"
  1829.         "xi"
  1830.         "pi"
  1831.         "rho"
  1832.         "sigma"
  1833.         "tau"
  1834.         "upsilon"
  1835.         "phi"
  1836.         "chi"
  1837.         "psi"
  1838.         "omega"
  1839.         }
  1840.     }
  1841.     {menu -n Greek2 -p interpretMenuItem {
  1842.         "capGamma"
  1843.         "capDelta"
  1844.         "capTheta"
  1845.         "capLambda"
  1846.         "capXi"
  1847.         "capPi"
  1848.         "capSigma"
  1849.         "capUpsilon"
  1850.         "capPhi"
  1851.         "capPsi"
  1852.         "capOmega"
  1853.         "(-"
  1854.         "varEpsilon"
  1855.         "varTheta"
  1856.         "varPi"
  1857.         "varRho"
  1858.         "varSigma"
  1859.         "varPhi"
  1860.         }
  1861.     }
  1862.         
  1863.     {menu -n BinaryOperators -p interpretMenuItem {
  1864.         "plusOrMinus"
  1865.         "minusOrPlus"
  1866.         "multiply"
  1867.         "divide"
  1868.         "asterisk"
  1869.         "star"
  1870.         "centerDot"
  1871.         "bullet"
  1872.         "circle"
  1873.         "bigCircle"
  1874.         "intersection"
  1875.         "union"
  1876.         "logicalAnd"
  1877.         "logicalOr"
  1878.         "setMinus"
  1879.         }
  1880.     }
  1881.     
  1882.     {menu -n Relations -p interpretMenuItem {
  1883.         "notEqual"
  1884.         "lessOrEqual"
  1885.         "greaterOrEqual"
  1886.         "subset"
  1887.         "superset"
  1888.         "subsetOrEqual"
  1889.         "supersetOrEqual"
  1890.         "elementOf"
  1891.         "equivalent"
  1892.         "similar"
  1893.         "similarEqual"
  1894.         "dotEqual"
  1895.         "approximate"
  1896.         "congruent"
  1897.         }
  1898.     }
  1899.     
  1900.     {menu -n LargeOperators -p interpretMenuItem {
  1901.         "sum"
  1902.         "product"
  1903.         "integral"
  1904.         "bigUnion"
  1905.         "bigIntersection"
  1906.         "bigAnd"
  1907.         "bigOr"
  1908.         }
  1909.     }
  1910.     
  1911.     {menu -n Arrows -p interpretMenuItem {
  1912.         "mapsTo"
  1913.         "leftArrow"
  1914.         "rightArrow"
  1915.         "left-rightArrow"
  1916.         "dblLeftArrow"
  1917.         "dblRightArrow"
  1918.         "dblLeft-rightArrow"
  1919.         }
  1920.     }
  1921.     
  1922.     {menu -n Dots -p interpretMenuItem {
  1923.         "centerDot"
  1924.         "bullet"
  1925.         "(-"
  1926.         "ellipsis"
  1927.         "centerDots"
  1928.         "verticalDots"
  1929.         "diagonalDots"
  1930.         }
  1931.     }
  1932.     
  1933.     {menu -n Symbols -p interpretMenuItem {
  1934.         "aleph"
  1935.         "emptySet"
  1936.         "negation"
  1937.         "forAll"
  1938.         "exists"
  1939.         "scriptL"
  1940.         "nabla"
  1941.         "partial"
  1942.         "infinity"
  1943.         "backslash"
  1944.         "angle"
  1945.         "box"
  1946.         "diamond"
  1947.         "triangle"
  1948.         }
  1949.     }
  1950.         
  1951.     {menu -n (Functions -p interpretMenuItem {
  1952.         }
  1953.     }
  1954.  
  1955.     {menu -n Delimiters -p interpretMenuItem {
  1956.         "parentheses"
  1957.         "brackets"
  1958.         "braces"
  1959.         "absoluteValue"
  1960.         "otherDelims…"
  1961.         "(-"
  1962.         "half-openInterval"
  1963.         "half-closedInterval"
  1964.         "(-"
  1965.         "bigParentheses"
  1966.         "bigBrackets"
  1967.         "bigBraces"
  1968.         "bigAbsoluteValue"
  1969.         "otherBigDelims…"
  1970.         "(-"
  1971.         "bigLeftBrace"
  1972.         "otherMixedBigDelims…"
  1973.         }
  1974.     }
  1975.         
  1976.     {menu -n mathAccents -p interpretMenuItem {
  1977.         "hat"
  1978.         "check"
  1979.         "breve"
  1980.         "acuteAccent"
  1981.         "graveAccent"
  1982.         "tilde"
  1983.         "bar"
  1984.         "vector"
  1985.         "dot"
  1986.         "dblDot"
  1987.         "(-"
  1988.         "wideHat"
  1989.         "wideTilde"
  1990.         "(-"
  1991.         "dotlessI"
  1992.         "dotlessJ"
  1993.         }
  1994.     }
  1995.     
  1996.     {menu -n Grouping -p interpretMenuItem {
  1997.         "underline"
  1998.         "overline"
  1999.         "underbrace"
  2000.         "overbrace"
  2001.         "(-"
  2002.         "stack"
  2003.         }
  2004.     }
  2005.     
  2006.     {menu -n Spacing -p interpretMenuItem {
  2007.         "thin"
  2008.         "negThin"
  2009.         "medium"
  2010.         "thick"
  2011.         "(-"
  2012.         "quad"
  2013.         "dblQuad"
  2014.         }
  2015.     }
  2016.     
  2017.     {menu -n MathStyle -p interpretMenuItem {
  2018.         "mathItalic"
  2019.         "calligraphic"
  2020.         "(-"
  2021.         "(fraktur"
  2022.         "(script"
  2023.         "(blackboardBold"
  2024.         "(-"
  2025.         "displayStyle"
  2026.         "textStyle"
  2027.         "scriptStyle"
  2028.         "scriptscriptStyle"
  2029.         }
  2030.     }
  2031. }
  2032.  
  2033.  
  2034. #############################################################################
  2035. #
  2036. # Special Key Bindings.
  2037. #
  2038. # abbreviations:  <o> = option, <z> = control, <s> = shift, <c> = command
  2039. #
  2040. #############################################################################
  2041.  
  2042. bind 0x14 <z> commentLine TeX
  2043. if {$optionIsMeta == "0"} then {
  2044.  
  2045.     #  use option for macros, escape for meta
  2046.  
  2047.     bind    'a'    <o>    alpha    "TeX"
  2048.     bind    'a'    <os>    angle    "TeX"
  2049.     bind    'a'    <oz>    forAll    "TeX"
  2050.     bind    'a'    <co>    acuteAccent    "TeX"
  2051.     
  2052.     bind    'b'    <o>    beta    "TeX"
  2053.     bind    'b'    <oz>    box    "TeX"
  2054.     bind    'b'    <co>    bar    "TeX"
  2055.     bind    'b'    <cs>    bold    "TeX"
  2056.     
  2057.     bind    'c'    <o>    chi    "TeX"
  2058.     bind    'c'    <co>    check    "TeX"
  2059.     bind    'c'    <cs>    citation    "TeX"
  2060.     bind    'c'    <cso>    calligraphic    "TeX"
  2061.     
  2062.     bind    'd'    <o>    delta    "TeX"
  2063.     bind    'd'    <os>    capDelta    "TeX"
  2064.     bind    'd'    <oz>    diamond    "TeX"
  2065.     bind    'd'    <co>    dot    "TeX"
  2066.     bind    'd'    <cso>    dblDot    "TeX"
  2067.     
  2068.     bind    'e'    <o>    epsilon    "TeX"
  2069.     bind    'e'    <os>    exists    "TeX"
  2070.     bind    'e'    <oz>    varEpsilon    "TeX"
  2071.     bind    'e'    <cs>    emphatic    "TeX"
  2072.     
  2073.     bind    'f'    <o>    phi    "TeX"
  2074.     bind    'f'    <os>    capPhi    "TeX"
  2075.     bind    'f'    <oz>    varPhi    "TeX"
  2076.     bind    'f'    <co>    fraction    "TeX"
  2077.     bind    'f'    <cs>    footnote    "TeX"
  2078.     
  2079.     bind    'g'    <o>    gamma    "TeX"
  2080.     bind    'g'    <os>    capGamma    "TeX"
  2081.     bind    'g'    <oz>    copyright    "TeX"
  2082.     bind    'g'    <co>    graveAccent    "TeX"
  2083.     
  2084.     bind    'h'    <o>    eta    "TeX"
  2085.     bind    'h'    <co>    hat    "TeX"
  2086.     bind    'h'    <cs>    smallCaps    "TeX"
  2087.     bind    'h'    <cso>    wideHat    "TeX"
  2088.     
  2089.     bind    'i'    <o>    iota    "TeX"
  2090.     bind    'i'    <oz>    dotlessI    "TeX"
  2091.     bind    'i'    <co>    integral    "TeX"
  2092.     bind    'i'    <cs>    italic    "TeX"
  2093.     bind    'i'    <cso>    mathItalic    "TeX"
  2094.     
  2095.     bind    'j'    <o>    partial    "TeX"
  2096.     bind    'j'    <oz>    dotlessJ    "TeX"
  2097.     
  2098.     bind    'k'    <o>    kappa    "TeX"
  2099.     
  2100.     bind    'l'    <o>    lambda    "TeX"
  2101.     bind    'l'    <os>    capLambda    "TeX"
  2102.     bind    'l'    <oz>    scriptL    "TeX"
  2103.     bind    'l'    <cs>    label    "TeX"
  2104.     
  2105.     bind    'm'    <o>    mu    "TeX"
  2106.     bind    'm'    <oz>    mapsTo    "TeX"
  2107.     bind    'm'    <co>    mbox    "TeX"
  2108.     bind    'm'    <cs>    mbox    "TeX"
  2109.     
  2110.     bind    'n'    <o>    nu    "TeX"
  2111.     bind    'n'    <os>    aleph    "TeX"
  2112.     bind    'n'    <oz>    intersection    "TeX"
  2113.     bind    'n'    <co>    nthRoot    "TeX"
  2114.     bind    'n'    <cs>    note    "TeX"
  2115.     
  2116.     bind    'o'    <o>    circle    "TeX"
  2117.     bind    'o'    <os>    bigCircle    "TeX"
  2118.     bind    'o'    <co>    overline    "TeX"
  2119.     bind    'o'    <cso>    overbrace    "TeX"
  2120.     
  2121.     bind    'p'    <o>    pi    "TeX"
  2122.     bind    'p'    <os>    capPi    "TeX"
  2123.     bind    'p'    <oz>    varPi    "TeX"
  2124.     bind    'p'    <co>    product    "TeX"
  2125.     bind    'p'    <cs>    pageRef    "TeX"
  2126.     
  2127.     bind    'q'    <o>    theta    "TeX"
  2128.     bind    'q'    <os>    capTheta    "TeX"
  2129.     bind    'q'    <oz>    varTheta    "TeX"
  2130.     
  2131.     bind    'r'    <o>    rho    "TeX"
  2132.     bind    'r'    <oz>    varRho    "TeX"
  2133.     bind    'r'    <co>    squareRoot    "TeX"
  2134.     bind    'r'    <cs>    roman    "TeX"
  2135.     
  2136.     bind    's'    <o>    sigma    "TeX"
  2137.     bind    's'    <os>    capSigma    "TeX"
  2138.     bind    's'    <oz>    varSigma    "TeX"
  2139.     bind    's'    <co>    sum    "TeX"
  2140.     bind    's'    <cs>    slanted    "TeX"
  2141.     
  2142.     bind    't'    <o>    tau    "TeX"
  2143.     bind    't'    <os>    dagger    "TeX"
  2144.     bind    't'    <oz>    triangle    "TeX"
  2145.     bind    't'    <co>    tilde    "TeX"
  2146.     bind    't'    <cs>    typewriter    "TeX"
  2147.     bind    't'    <cso>    wideTilde    "TeX"
  2148.     
  2149.     bind    'u'    <o>    upsilon    "TeX"
  2150.     bind    'u'    <os>    capUpsilon    "TeX"
  2151.     bind    'u'    <oz>    union    "TeX"
  2152.     bind    'u'    <co>    underline    "TeX"
  2153.     bind    'u'    <cso>    underbrace    "TeX"
  2154.     
  2155.     bind    'v'    <o>    nabla    "TeX"
  2156.     bind    'v'    <oz>    logicalOr    "TeX"
  2157.     bind    'v'    <co>    vector    "TeX"
  2158.     
  2159.     bind    'w'    <o>    omega    "TeX"
  2160.     bind    'w'    <os>    capOmega    "TeX"
  2161.     bind    'w'    <oz>    logicalAnd    "TeX"
  2162.     bind    'w'    <cs>    sansSerif    "TeX"
  2163.     
  2164.     bind    'x'    <o>    xi    "TeX"
  2165.     bind    'x'    <os>    capXi    "TeX"
  2166.     bind    'x'    <oz>    multiply    "TeX"
  2167.     bind    'x'    <cs>    crossRef    "TeX"
  2168.     
  2169.     bind    'y'    <o>    psi    "TeX"
  2170.     bind    'y'    <os>    capPsi    "TeX"
  2171.     
  2172.     bind    'z'    <o>    zeta    "TeX"
  2173.     
  2174.     bind    '\ '    <o>    thin    "TeX"
  2175.     bind    '\ '    <os>    negThin    "TeX"
  2176.     bind    '\ '    <oz>    medium    "TeX"
  2177.     bind    '\ '    <co>    thick    "TeX"
  2178.     bind    '\ '    <cs>    quad    "TeX"
  2179.     bind    '\ '    <cso>    dblQuad    "TeX"
  2180.     
  2181.     bind    ','    <o>    lessOrEqual    "TeX"
  2182.     bind    ','    <os>    subset    "TeX"
  2183.     bind    ','    <oz>    subsetOrEqual    "TeX"
  2184.     bind    ','    <co>    subscript    "TeX"
  2185.     
  2186.     bind    '.'    <o>    greaterOrEqual    "TeX"
  2187.     bind    '.'    <os>    superset    "TeX"
  2188.     bind    '.'    <oz>    supersetOrEqual    "TeX"
  2189.     bind    '.'    <co>    superscript    "TeX"
  2190.     
  2191.     bind    '/'    <o>    divide    "TeX"
  2192.     bind    '/'    <co>    fraction    "TeX"
  2193.     
  2194.     bind    '\;'    <o>    ellipsis    "TeX"
  2195.     bind    '\;'    <os>    centerDots    "TeX"
  2196.     bind    '\;'    <oz>    verticalDots    "TeX"
  2197.     bind    '\;'    <co>    diagonalDots    "TeX"
  2198.     
  2199.     # apostrophe:
  2200.     bind    0x27    <co>    acuteAccent    "TeX"
  2201.     bind    0x27    <cs>    quotes    "TeX"
  2202.     bind    0x27    <cso>    dblQuotes    "TeX"
  2203.  
  2204.     bind    '\['    <o>    brackets    "TeX"
  2205.     bind    '\['    <os>    braces    "TeX"
  2206.     bind    '\['    <co>    bigBrackets    "TeX"
  2207.     bind    '\['    <cso>    bigBraces    "TeX"
  2208.  
  2209.     bind    '\]'    <o>    displayStyle    "TeX"
  2210.     bind    '\]'    <os>    textStyle    "TeX"
  2211.     bind    '\]'    <oz>    scriptStyle    "TeX"
  2212.     bind    '\]'    <co>    scriptscriptStyle    "TeX"
  2213.     bind    '\]'    <cso>    bigLeftBrace    "TeX"
  2214.     
  2215.     bind    '\'    <o>    backslash    "TeX"
  2216.     bind    '\'    <os>    absoluteValue    "TeX"
  2217.     bind    '\'    <oz>    setMinus    "TeX"
  2218.     bind    '\'    <co>    bigAbsoluteValue    "TeX"
  2219.     bind    '\'    <cs>    "oneParameter"    "TeX"
  2220.     bind    '\'    <cso>    "twoParameters"    "TeX"
  2221.     
  2222.     bind    '`'    <co>    graveAccent    "TeX"
  2223.     bind    '`'    <cso>    tilde    "TeX"
  2224.         
  2225.     # Change to latexMath and latexDisplaymath, if desired:
  2226.     bind    '4'    <co>    texMath    "TeX"
  2227.     bind    '4'    <cso>    texDisplaymath    "TeX"
  2228.     
  2229.     bind    '5'    <o>    infinity    "TeX"
  2230.     
  2231.     bind    '6'    <o>    sectionMark    "TeX"
  2232.     bind    '6'    <co>    superscript    "TeX"
  2233.     
  2234.     bind    '7'    <o>    paragraphMark    "TeX"
  2235.     
  2236.     bind    '8'    <o>    bullet    "TeX"
  2237.     bind    '8'    <os>    asterisk    "TeX"
  2238.     bind    '8'    <oz>    centerDot    "TeX"
  2239.     
  2240.     bind    '9'    <os>    parentheses    "TeX"
  2241.     bind    '9'    <co>    bigParentheses    "TeX"
  2242.     
  2243.     bind    '0'    <oz>    emptySet    "TeX"
  2244.     
  2245.     bind    '-'    <o>    similar    "TeX"
  2246.     bind    '-'    <os>    minusOrPlus    "TeX"
  2247.     bind    '-'    <oz>    negation    "TeX"
  2248.     bind    '-'    <co>    subscript    "TeX"
  2249.     
  2250.     bind    '='    <o>    notEqual    "TeX"
  2251.     bind    '='    <os>    plusOrMinus    "TeX"
  2252.     bind    '='    <oz>    approximate    "TeX"
  2253.     bind    '='    <co>    bar    "TeX"
  2254.     
  2255.     bind    F5    <o>    math    "TeX"
  2256.     bind    F5    <os>    displaymath    "TeX"
  2257.     bind    F5    <oz>    equation    "TeX"
  2258.     
  2259.     bind    F6    <o>    "myArray"    "TeX"
  2260.     bind    F6    <os>    "eqnarray"    "TeX"
  2261.     bind    F6    <oz>    "eqnarrayStar"    "TeX"
  2262.     
  2263.     bind    F7    <o>    "enumerate"    "TeX"
  2264.     bind    F7    <os>    "itemize"    "TeX"
  2265.     bind    F7    <oz>    "description"    "TeX"
  2266.     
  2267.     bind    F8    <o>    "tabular"    "TeX"
  2268.     bind    F8    <os>    tabbing    "TeX"
  2269.     
  2270.     bind    F9    <o>    figure    "TeX"
  2271.     bind    F9    <os>    table    "TeX"
  2272.     bind    F9    <oz>    slide    "TeX"
  2273.     
  2274.     bind    F10    <o>    verbatim    "TeX"
  2275.     bind    F10    <os>    quote    "TeX"
  2276.     bind    F10    <oz>    quotation    "TeX"
  2277.     bind    F10    <co>    verse    "TeX"
  2278.     
  2279.     bind    F11    <o>    "index"    "TeX"
  2280.     bind    F11    <os>    "bibliography"    "TeX"
  2281.     
  2282.     bind    F12    <o>    "general"    "TeX"
  2283.     
  2284.     # tab:
  2285.     bind    0x30    nextTabStop    "TeX"
  2286.     bind    0x30    <s>     previousTabStop    "TeX"
  2287.     
  2288. } else {
  2289.     
  2290.     #    bind    macros    to    option-control,    use    option    as    meta
  2291.     
  2292.     bind    'a'    <zo>    alpha    "TeX"
  2293.     bind    'a'    <zos>    angle    "TeX"
  2294.     # bind    'a'    <oz>    forAll    "TeX"
  2295.     bind    'a'    <zco>    acuteAccent    "TeX"
  2296.     
  2297.     bind    'b'    <zo>    beta    "TeX"
  2298.     # bind    'b'    <oz>    box    "TeX"
  2299.     bind    'b'    <zco>    bar    "TeX"
  2300.     bind    'b'    <zcs>    bold    "TeX"
  2301.     
  2302.     bind    'c'    <zo>    chi    "TeX"
  2303.     bind    'c'    <zco>    check    "TeX"
  2304.     bind    'c'    <zcs>    citation    "TeX"
  2305.     bind    'c'    <zcso>    calligraphic    "TeX"
  2306.     
  2307.     bind    'd'    <zo>    delta    "TeX"
  2308.     bind    'd'    <zos>    capDelta    "TeX"
  2309.     # bind    'd'    <oz>    diamond    "TeX"
  2310.     bind    'd'    <zco>    dot    "TeX"
  2311.     bind    'd'    <zcso>    dblDot    "TeX"
  2312.     
  2313.     bind    'e'    <zo>    epsilon    "TeX"
  2314.     bind    'e'    <zos>    exists    "TeX"
  2315.     # bind    'e'    <oz>    varEpsilon    "TeX"
  2316.     bind    'e'    <zcs>    emphatic    "TeX"
  2317.     
  2318.     bind    'f'    <zo>    phi    "TeX"
  2319.     bind    'f'    <zos>    capPhi    "TeX"
  2320.     # bind    'f'    <oz>    varPhi    "TeX"
  2321.     bind    'f'    <zco>    fraction    "TeX"
  2322.     bind    'f'    <zcs>    footnote    "TeX"
  2323.     
  2324.     bind    'g'    <zo>    gamma    "TeX"
  2325.     bind    'g'    <zos>    capGamma    "TeX"
  2326.     # bind    'g'    <oz>    copyright    "TeX"
  2327.     bind    'g'    <zco>    graveAccent    "TeX"
  2328.     
  2329.     bind    'h'    <zo>    eta    "TeX"
  2330.     bind    'h'    <zco>    hat    "TeX"
  2331.     bind    'h'    <zcs>    smallCaps    "TeX"
  2332.     bind    'h'    <zcso>    wideHat    "TeX"
  2333.     
  2334.     bind    'i'    <zo>    iota    "TeX"
  2335.     # bind    'i'    <oz>    dotlessI    "TeX"
  2336.     bind    'i'    <zco>    integral    "TeX"
  2337.     bind    'i'    <zcs>    italic    "TeX"
  2338.     bind    'i'    <zcso>    mathItalic    "TeX"
  2339.     
  2340.     bind    'j'    <zo>    partial    "TeX"
  2341.     # bind    'j'    <oz>    dotlessJ    "TeX"
  2342.     
  2343.     bind    'k'    <zo>    kappa    "TeX"
  2344.     
  2345.     bind    'l'    <zo>    lambda    "TeX"
  2346.     bind    'l'    <zos>    capLambda    "TeX"
  2347.     # bind    'l'    <oz>    scriptL    "TeX"
  2348.     bind    'l'    <zcs>    label    "TeX"
  2349.     
  2350.     bind    'm'    <zo>    mu    "TeX"
  2351.     # bind    'm'    <oz>    mapsTo    "TeX"
  2352.     bind    'm'    <zco>    mbox    "TeX"
  2353.     bind    'm'    <zcs>    mbox    "TeX"
  2354.     
  2355.     bind    'n'    <zo>    nu    "TeX"
  2356.     bind    'n'    <zos>    aleph    "TeX"
  2357.     # bind    'n'    <oz>    intersection    "TeX"
  2358.     bind    'n'    <zco>    nthRoot    "TeX"
  2359.     bind    'n'    <zcs>    note    "TeX"
  2360.     
  2361.     bind    'o'    <zo>    circle    "TeX"
  2362.     bind    'o'    <zos>    bigCircle    "TeX"
  2363.     bind    'o'    <zco>    overline    "TeX"
  2364.     bind    'o'    <zcso>    overbrace    "TeX"
  2365.     
  2366.     bind    'p'    <zo>    pi    "TeX"
  2367.     bind    'p'    <zos>    capPi    "TeX"
  2368.     # bind    'p'    <oz>    varPi    "TeX"
  2369.     bind    'p'    <zco>    product    "TeX"
  2370.     bind    'p'    <zcs>    pageRef    "TeX"
  2371.     
  2372.     bind    'q'    <zo>    theta    "TeX"
  2373.     bind    'q'    <zos>    capTheta    "TeX"
  2374.     # bind    'q'    <oz>    varTheta    "TeX"
  2375.     
  2376.     bind    'r'    <zo>    rho    "TeX"
  2377.     # bind    'r'    <oz>    varRho    "TeX"
  2378.     bind    'r'    <zco>    squareRoot    "TeX"
  2379.     bind    'r'    <zcs>    roman    "TeX"
  2380.     
  2381.     bind    's'    <zo>    sigma    "TeX"
  2382.     bind    's'    <zos>    capSigma    "TeX"
  2383.     # bind    's'    <oz>    varSigma    "TeX"
  2384.     bind    's'    <zco>    sum    "TeX"
  2385.     bind    's'    <zcs>    slanted    "TeX"
  2386.     
  2387.     bind    't'    <zo>    tau    "TeX"
  2388.     bind    't'    <zos>    dagger    "TeX"
  2389.     # bind    't'    <oz>    triangle    "TeX"
  2390.     bind    't'    <zco>    tilde    "TeX"
  2391.     bind    't'    <zcs>    typewriter    "TeX"
  2392.     bind    't'    <zcso>    wideTilde    "TeX"
  2393.     
  2394.     bind    'u'    <zo>    upsilon    "TeX"
  2395.     bind    'u'    <zos>    capUpsilon    "TeX"
  2396.     # bind    'u'    <oz>    union    "TeX"
  2397.     bind    'u'    <zco>    underline    "TeX"
  2398.     bind    'u'    <zcso>    underbrace    "TeX"
  2399.     
  2400.     bind    'v'    <zo>    nabla    "TeX"
  2401.     # bind    'v'    <oz>    logicalOr    "TeX"
  2402.     bind    'v'    <zco>    vector    "TeX"
  2403.     
  2404.     bind    'w'    <zo>    omega    "TeX"
  2405.     bind    'w'    <zos>    capOmega    "TeX"
  2406.     # bind    'w'    <oz>    logicalAnd    "TeX"
  2407.     bind    'w'    <zcs>    sansSerif    "TeX"
  2408.     
  2409.     bind    'x'    <zo>    xi    "TeX"
  2410.     bind    'x'    <zos>    capXi    "TeX"
  2411.     # bind    'x'    <oz>    multiply    "TeX"
  2412.     bind    'x'    <zcs>    crossRef    "TeX"
  2413.     
  2414.     bind    'y'    <zo>    psi    "TeX"
  2415.     bind    'y'    <zos>    capPsi    "TeX"
  2416.     
  2417.     bind    'z'    <zo>    zeta    "TeX"
  2418.     
  2419.     bind    '\ '    <zo>    thin    "TeX"
  2420.     bind    '\ '    <zos>    negThin    "TeX"
  2421.     # bind    '\ '    <oz>    medium    "TeX"
  2422.     bind    '\ '    <zco>    thick    "TeX"
  2423.     bind    '\ '    <zcs>    quad    "TeX"
  2424.     bind    '\ '    <zcso>    dblQuad    "TeX"
  2425.     
  2426.     bind    ','    <zo>    lessOrEqual    "TeX"
  2427.     bind    ','    <zos>    subset    "TeX"
  2428.     # bind    ','    <oz>    subsetOrEqual    "TeX"
  2429.     bind    ','    <zco>    subscript    "TeX"
  2430.     
  2431.     bind    '.'    <zo>    greaterOrEqual    "TeX"
  2432.     bind    '.'    <zos>    superset    "TeX"
  2433.     # bind    '.'    <oz>    supersetOrEqual    "TeX"
  2434.     bind    '.'    <zco>    superscript    "TeX"
  2435.     
  2436.     bind    '/'    <zo>    divide    "TeX"
  2437.     bind    '/'    <zco>    fraction    "TeX"
  2438.     
  2439.     bind    '\;'    <zo>    ellipsis    "TeX"
  2440.     bind    '\;'    <zos>    centerDots    "TeX"
  2441.     # bind    '\;'    <oz>    verticalDots    "TeX"
  2442.     bind    '\;'    <zco>    diagonalDots    "TeX"
  2443.     
  2444.     # apostrophe:
  2445.     bind    0x27    <zco>    acuteAccent    "TeX"
  2446.     bind    0x27    <zcs>    quotes    "TeX"
  2447.     bind    0x27    <zcso>    dblQuotes    "TeX"
  2448.  
  2449.     bind    '\['    <zo>    brackets    "TeX"
  2450.     bind    '\['    <zos>    braces    "TeX"
  2451.     bind    '\['    <zco>    bigBrackets    "TeX"
  2452.     bind    '\['    <zcso>    bigBraces    "TeX"
  2453.  
  2454.     bind    '\]'    <zo>    displayStyle    "TeX"
  2455.     bind    '\]'    <zos>    textStyle    "TeX"
  2456.     # bind    '\]'    <oz>    scriptStyle    "TeX"
  2457.     bind    '\]'    <zco>    scriptscriptStyle    "TeX"
  2458.     bind    '\]'    <zcso>    bigLeftBrace    "TeX"
  2459.     
  2460.     bind    '\'    <zo>    backslash    "TeX"
  2461.     bind    '\'    <zos>    absoluteValue    "TeX"
  2462.     # bind    '\'    <oz>    setMinus    "TeX"
  2463.     bind    '\'    <zco>    bigAbsoluteValue    "TeX"
  2464.     bind    '\'    <zcs>    "oneParameter"    "TeX"
  2465.     bind    '\'    <zcso>    "twoParameters"    "TeX"
  2466.     
  2467.     bind    '`'    <zco>    graveAccent    "TeX"
  2468.     bind    '`'    <zcso>    tilde    "TeX"
  2469.     
  2470.     # Change to latexMath and latexDisplaymath, if desired:
  2471.     bind    '4'    <zco>    texMath    "TeX"
  2472.     bind    '4'    <zcso>    texDisplaymath    "TeX"
  2473.     
  2474.     bind    '5'    <zo>    infinity    "TeX"
  2475.     
  2476.     bind    '6'    <zo>    sectionMark    "TeX"
  2477.     bind    '6'    <zco>    superscript    "TeX"
  2478.     
  2479.     bind    '7'    <zo>    paragraphMark    "TeX"
  2480.     
  2481.     bind    '8'    <zo>    bullet    "TeX"
  2482.     bind    '8'    <zos>    asterisk    "TeX"
  2483.     # bind    '8'    <oz>    centerDot    "TeX"
  2484.     
  2485.     bind    '9'    <zos>    parentheses    "TeX"
  2486.     bind    '9'    <zco>    bigParentheses    "TeX"
  2487.     
  2488.     # bind    '0'    <oz>    emptySet    "TeX"
  2489.     
  2490.     bind    '-'    <zo>    similar    "TeX"
  2491.     bind    '-'    <zos>    minusOrPlus    "TeX"
  2492.     # bind    '-'    <oz>    negation    "TeX"
  2493.     bind    '-'    <zco>    subscript    "TeX"
  2494.     
  2495.     bind    '='    <zo>    notEqual    "TeX"
  2496.     bind    '='    <zos>    plusOrMinus    "TeX"
  2497.     # bind    '='    <oz>    approximate    "TeX"
  2498.     bind    '='    <zco>    bar    "TeX"
  2499.     
  2500.     bind    F5    <zo>    math    "TeX"
  2501.     bind    F5    <zos>    displaymath    "TeX"
  2502.     # bind    F5    <oz>    equation    "TeX"
  2503.     
  2504.     bind    F6    <zo>    "myArray"    "TeX"
  2505.     bind    F6    <zos>    "eqnarray"    "TeX"
  2506.     # bind    F6    <oz>    "eqnarrayStar"    "TeX"
  2507.     
  2508.     bind    F7    <zo>    "enumerate"    "TeX"
  2509.     bind    F7    <zos>    "itemize"    "TeX"
  2510.     # bind    F7    <oz>    "description"    "TeX"
  2511.     
  2512.     bind    F8    <zo>    "tabular"    "TeX"
  2513.     bind    F8    <zos>    tabbing    "TeX"
  2514.     
  2515.     bind    F9    <zo>    figure    "TeX"
  2516.     bind    F9    <zos>    table    "TeX"
  2517.     # bind    F9    <oz>    slide    "TeX"
  2518.     
  2519.     bind    F10    <zo>    verbatim    "TeX"
  2520.     bind    F10    <zos>    quote    "TeX"
  2521.     # bind    F10    <oz>    quotation    "TeX"
  2522.     bind    F10    <zco>    verse    "TeX"
  2523.     
  2524.     bind    F11    <zo>    "index"    "TeX"
  2525.     bind    F11    <zos>    "bibliography"    "TeX"
  2526.     
  2527.     bind    F12    <zo>    "general"    "TeX"
  2528.  
  2529.     # tab:
  2530.     bind    0x30    nextTabStop    "TeX"
  2531.     bind    0x30    <s>     previousTabStop    "TeX"
  2532.     
  2533. }
  2534.  
  2535. #================================================================================
  2536. # Random nonsense
  2537. #================================================================================
  2538.  
  2539. proc nextSubSection {} {
  2540.     set res [search -f 1 -r 1 -n {(section|chapter)\{} [nextLineStart [getPos]]]
  2541.     if {[string length $res]} {
  2542.         goto [lineStart [lindex $res 0]]
  2543.     } else {
  2544.         beep
  2545.     }
  2546. }
  2547. bind 'n' <zs> nextSubSection "TeX"
  2548.  
  2549. proc prevSubSection {} {
  2550.     set res [search -f 0 -r 1 -n {(section|chapter)\{} [lineStart [getPos]]]
  2551.     if {[string length $res]} {
  2552.         goto [lineStart [lindex $res 0]]
  2553.     } else {
  2554.         beep
  2555.     }
  2556. }
  2557. bind 'p' <zs> prevSubSection "TeX"
  2558.  
  2559.  
  2560. proc nextSection {} {
  2561.     set res [search -f 1 -r 1 -n {\\(section|chapter)\{} [nextLineStart [getPos]]]
  2562.     if {[string length $res]} {
  2563.         goto [lineStart [lindex $res 0]]
  2564.     } else {
  2565.         beep
  2566.     }
  2567. }
  2568. bind 'n' <zsc> nextSection "TeX"
  2569.  
  2570. proc prevSection {} {
  2571.     set res [search -f 0 -r 1 -n {\\(section|chapter)\{} [expr [lineStart [getPos]]-1]]
  2572.     if {[string length $res]} {
  2573.         goto [lineStart [lindex $res 0]]
  2574.     } else {
  2575.         beep
  2576.     }
  2577. }
  2578. bind 'p' <zsc> prevSection "TeX"
  2579.  
  2580. set texKeyWords { diff }
  2581. regModeKeywords -e {%} -m {\\} -c red -k blue TeX $texKeyWords
  2582.